import cv2
import os
import glob
from skimage import exposure, morphology, color, img_as_bool, img_as_ubyte
import numpy as np

path = "/home/jiayu/Desktop/Jimmy/1219(分六组)/600-1219_all_nerve/gt/"

for file in glob.glob(os.path.join(path, '*')):
    image = cv2.imread(file,1)
    basename = os.path.basename(file)
    # image = img_as_bool(color.rgb2gray(image))
    imgage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    #
    skelton = morphology.skeletonize(image)                         # 提取骨架
    #
    # skimage_to_opencv  必须进行库的转换，才能利用cv2.里面的膨胀操作
    skelton = img_as_ubyte(skelton)    ## this process is important!!!
    # skelton = cv2.cvtColor(skelton, cv2.COLOR_GRAY2RGB)
    kernel = np.ones((3,3), np.uint8)
    img = cv2.dilate(image, kernel, iterations=1)                      #    膨胀
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    ret, thred = cv2.threshold(img, 10, 255, cv2.THRESH_BINARY)


# save_name = "/home/imed/视频/Corneal_cross_val1/predict1/xihua/" + os.path.basename(file)
    save_name = "/home/jiayu/Desktop/Jimmy/1219(分六组)/600-1219_all_nerve/gt3/" + basename

    cv2.imwrite(save_name, thred)

print('\tdone!')